package com.tmt.im.service.service;

import com.tmt.im.common.pojo.IMUserPoJo;
import com.tmt.im.common.store.Constant;
import lombok.extern.slf4j.Slf4j;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/8/25 22:27
 * @Version 1.0
 **/
@Slf4j
@Service
public class IgniteService {

    private final Ignite ignite;

    public IgniteService(Ignite ignite) {
        this.ignite = ignite;
    }

    public boolean isLogout(Long userId, String curUsername) {
        IgniteCache<Long, String> tmpCache = ignite.cache(Constant.LOGOUT_USER_CACHE_NAME);
        if (tmpCache != null) {
            String username = tmpCache.get(userId);
            if (Objects.equals(username, curUsername)) {
                return true;
            }
        }
        return false;
    }

    public boolean isInvalidToken(String accessToken){
        IgniteCache<String, String> cache = ignite.cache(Constant.INVALID_TOKEN_CACHE_NAME);
        if (cache != null) {
            return cache.get(accessToken) != null;
        }
        return false;
    }
}
